home *** CD-ROM | disk | FTP | other *** search
-
- /* Functions that aid in testing */
-
- /* Round to specified number of digits */
- RoundTo(x_IsNumber, prec_IsPositiveInteger) <-- N(Round(x*10^prec)*10^(-prec));
-
- /* Logging functions */
- // curline:=0;
-
- /*
- Function("StartTests",{})
- [
- curline:=0;
- ];
- */
- /*
- Function("NextTest",{aLeft})
- [
- // curline++;
- WriteString("
- Test suite for ":aLeft:" : "
- );
- NewLine();
- ];
- */
- /*
- Function("Testing",{aLeft})
- [
- WriteString(aLeft); NewLine();
- ];
- */
-
- Function("KnownFailure",{expr})
- [
- Local(rfail);
- Echo({"Known failure:"});
- Set(rfail,Eval(expr));
- If(rfail,Echo({"Failure resolved!"}));
- ];
- HoldArg("KnownFailure",expr);
-
- Function("Verify",{aLeft,aRight})
- [
- If (Not(Equals(Eval(aLeft),aRight)),
- [
- WriteString("******************");
- NewLine();
- Write(aLeft);
- WriteString(" evaluates to ");
- Write(Eval(aLeft));
- WriteString(" which differs from ");
- Write(aRight);
- NewLine();
- WriteString("******************");
- NewLine();
- False;
- ],
- True
- );
- ];
- /*
- HoldArg("Verify",aLeft);
- HoldArg("Verify",aRight);
- */
-
- Function("LogicVerify",{aLeft,aRight})
- [
- If(aLeft != aRight,
- Verify(CanProve(aLeft => aRight),True)
- );
- ];
-
-
- f1(x,n,m):=(x^n-1)*(x^m-1);
- f2(x,n,m):=x^(n+m)-(x^n)-(x^m)+1;
-
- VerifyArithmetic(x,n,m):=
- [
- /*
- WriteString("Checking arithmetic with ");
- Write(x);Space();
- Write(n);Space();
- Write(m);NewLine();
- */
- Verify(f1(x,n,m),f2(x,n,m));
- ];
- RandVerifyArithmetic(_n)<--
- [
- While(n>0)
- [
- n--;
- VerifyArithmetic(MathFloor(300*Random()),MathFloor(80*Random()),MathFloor(90*Random()));
- ];
- ];
-
- VerifyDiv(_u,_v) <--
- [
- Local(q,r);
- q:=Div(u,v);
- r:=Rem(u,v);
-
- Verify(Expand(u),Expand(q*v+r));
- ];
-
- 10 # EchoInternal(string_IsString) <--
- [
- WriteString(string);
- ];
-
- 20 # EchoInternal(_item) <--
- [
- Write(item);Space();
- ];
-
- 10 # Echo(list_IsList)<--
- [
- ForEach(item,list) EchoInternal(item);
- NewLine();
- ];
- 20 # Echo(_item)<--
- [
- EchoInternal(item);
- NewLine();
- ];
-
-
- Function("BenchCall",{expr})
- [
- Echo({"In> ",expr});
- WriteString("<font color=ff0000>");
- Eval(expr);
- WriteString("</font>");
- True;
- ];
- HoldArg("BenchCall",expr);
-
- Function("BenchShow",{expr})
- [
- Echo({"In> ",expr});
- WriteString("<font color=ff0000> ");
- Echo({"Out> ",Eval(expr),"</font>"});
- True;
- ];
- HoldArg("BenchShow",expr);
-
-
-
-
- /* Testing Yacas functionality by checking expressions against correct
- answer.
- Use with algebraic expressions only, since we need Simplify() for that to work.
- */
-
- Function ("TestYacas", {expr, ans})
- [
- If (Simplify(Eval(expr)-ans)=0, True,
- [
- WriteString("******************");
- NewLine();
- Write(Hold(expr));
- WriteString(" evaluates to ");
- NewLine();
- Write(Eval(expr));
- NewLine();
- WriteString(" which differs from ");
- NewLine();
- Write(ans);
- NewLine();
- WriteString("******************");
- NewLine();
- False;
- ]
- );
- ];
-
- HoldArg("TestYacas", expr);
- HoldArg("TestYacas", ans);
-
-
-
-
-
-
-
-